<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=yes">
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
<title>订单详情</title>
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
<link rel="stylesheet" type="text/css" href="/static/css/shoujisc.css">
<script type="text/javascript" src="/static/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="/static/js/myinit.js"></script>
<style type="text/css">
.myzhifumima {
	border-left: grey 1px solid;
	padding-left:1px;
	width: 30px;
	height: 36px;
	display: inline-block;
}

.myzhifumimatian{
	background:url(/static/img/dian.png) no-repeat center;
}

</style>
</head>

<body style="font-size:14px;" >
<div class="sjsc-title2" style="height:44px">
    <h3 class="sjsc-t2l" style="height:44px;line-height:44px;" >订单详情</h3>
    <a href="javascript:history.back();" class="sjsc-t2r" style="height:44px;line-height:44px;background-image:url('/static/img/back.png');width:44px;background-position:center;background-repeat:no-repeat;background-size:30px;30px;"></a> </div>
<div class="qrdd-info2" style="margin-top: 0px;">
    <div class="qrdd-xian" style="font-size:14px">
        <p class="qrdd-p1" style="font-size:14px">订单编号：<span style="font-size:14px" id="orderid"></span>　<span style="color:#FF2F2F;float:right;margin-right:10px;margin-top:3px;font-size:14px" id="status"></span></p>
        <p class="qrdd-p1" style="font-size:14px">感谢您在天天惠购物，欢迎您的再次光临！</p>
    </div>
    <div class="qrdd-xian"> <span id="shouhuophone" style="float:right;margin-right:20px;font-size:14px"></span>
        <p class="qrdd-p1" id="shouname" style="font-size:14px"></p>
        <p class="qrdd-p1" id="shouhuoaddr" style="font-size:14px"></p>
    </div>
    <br />
    <div class="my-k1" >
        <ul class="my-p1">
            <li class="my-spl f-l" id="time"></li>
            <div style="clear:both;"></div>
        </ul>
        <div id="shangpinlist"></div>
        <div id="youhui" style="text-align:right"></div>
        <div class="my-p2" style="line-height: 30px;" id="order_action">共<span style="color:#D12424" id="all_count">'+item.count+'</span>件商品合计:<span style="color:#D12424" id="order_price"></span></div>
    </div>
    <div> </div>
</div>


<div id="zhifudialog_container" style="position:absolute;top:0px;left:0px;height:100%;background-color:rgba(0,0,0,0.25);width:100%;display:none;;text-align:center">
    <div id="zhifu_dialog_body" style="background-color:white;border-radius:10px;display:inline-block;width:320px;max-width:80%">
        <div style="height:40px;line-height:40px;border-bottom:green 1px solid;font-size:large;position:relative">
            <div style="height:40px;line-height:40px;color:#CCC;position:absolute;left:20px" id="zhifu_dialog_cancel">X</div>
            <div style="height:40px;line-height:40px">请输入支付密码</div>
        </div>
        <div style="margin-top:25px">我的余额支付</div>
        <div style="height: 50px; line-height: 50px; font-size: xx-large;">￥<span id="zhifu_dialog_jine">11.00</span></div>
        <div style="position: relative; min-height: 60px;;margin-top:10px">
            <input id="password11" style="position:absolute;top:0px;left:-1000px" autofocus type="password">
            <div style="position: absolute; left: 1em; right: 1em; height: 36px;" id="fakebody">
                <div style="text-align:center">
                    <div style="border: 1px solid gray; display: inline-block; height: 36px;">
                        <div class="myzhifumima" style="border-left:none"></div>
                        <div class="myzhifumima"></div>
                        <div class="myzhifumima"></div>
                        <div class="myzhifumima"></div>
                        <div class="myzhifumima"></div>
                        <div class="myzhifumima"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
		var oid = getUrldata('ORDERID');
		var openid=getUrldata('OPENID');
		var pingjia_all={};
		$.ajaxSettings.async = false;
		$.ajaxSettings.cache=false;

		
		$(document).ready(function(){
			initOrder();
		
		});
	
		
	
	
	
	/*
		function initAorderitem(oid,ispingjia){
			var url = '/webserver/api/v1/orderitem/?format=json&order='+oid;
			$.getJSON(url,function(rs){
				var objects=rs.objects;
				$.each(objects,function(index,item){
					var htm='';
					if(ispingjia=='确认收货'){
						htm='<div class="my-p2" style="border-top:none"><button class="my-btn1 f-r">评价</button></div>';
					}
					$('#shangpinlist').append('<div style="position:relative;background-color:#f4f4f4;margin-top:2px;"><div style="border: 1px solid #D6D6D6;width:80px;height:80px;background-image:url(\''+item.goods.image_thumb+'\');background-position:center;background-repeat:no-repeat;background-size:auto 70px;"></div><div style="position:absolute;left:90px;right:100px;display:block;height:80px;top:0px"><div style="margin-top:6px;font-size:14px;">'+item.goods.name+'</div><p class="my-dp1">'+item.good_format+'</p></div><div style="position:absolute;width:100px;right:0px;display:block;height:80px;top:0px"><p class="my-dp1 f-r" style="text-align:right;padding-top:3px;padding-right:3px">价格：<span style="color:#D12424">￥'+item.goods.price+'</span><br>×'+item.count+'</p></div><div style="position:absolute;right:0px;bottom:0px;text-align:right">'+htm+'</div></div>');
					$('#shangpinlist button').click(function(){
						document.location.href="pingjia.html?ORDERID="+oid+"&GOODID="+item.goods.id+"&OPENID="+openid;
					});
					
					/*
					.append('<dl class="my-dl1" style="background-color:#f4f4f4;margin-top:2px"><div style=""></div><dt><a href="#"><img src="'+item.goods.image_thumb+'"></a></dt><dd style="width:50%"></dd><div style="clear:both;"></div></dl>');
					*/
					
				/*	 
				});
			});
			
			
		
		}
		*/
		function initOrder(){
			var url="/webserver/api/v1/orderitem/?format=json&order="+oid;
			$.getJSON(url,function(rs){
				var object = rs.objects[0];
				var order = object.order;
				$('#orderid').html(order.id);
				
				$('#all_count').html(order.count);
				$('#order_price').html("￥"+order.price);
				var htm="";
				var htm_status=order.status;
				if(order.status=='已下单'){
					htm='<button class="my-btn1 f-r">支付</button><button class="my-btn1 f-r">取消</button>';
				}else if(order.status=='已取消'){
					htm="";
				}else if(order.status=='已支付'){
					htm="";
				}else if(order.status=='已发货'){
					htm='<button class="my-btn1 f-r">确认收货</button>';
					
				}else if(order.status=='收货'){
					 
				}else if(order.status=="确认收货"){
					htm_status="已收货";
						
				}
				$('#status').html(htm_status);
				$('#shouname').html(order.custname);
				$('#shouhuophone').html(order.phoneno);
			 
				$('#shouhuoaddr').html(order.cityname+order.detailAdrinfo);
				$('#order_action').append(htm);
			 
				var time=order.modified;
				time=time.replace("T"," ");
				$('#time').html(time);
				var htm="";
				var status=order.status;
				var goods=object.goods;
				
				
				var cuxiaoid=order.deductionitemid;
				if(cuxiaoid!=null&&cuxiaoid!=0){
					initayouhui(cuxiaoid);
				}
				
				 
				$.each(rs.objects,function(index,item){
					var pingjia_htm='';
					if(status=='确认收货'){
						
						pingjia_htm=ispingjia(oid,item.goods.id);
						 
					}
					$('#shangpinlist').append('<div id="'+item.goods.id+'" style="position:relative;background-color:#f4f4f4;margin-top:2px;"><div style="border: 1px solid #D6D6D6;width:80px;height:80px;background-image:url(\''+item.goods.image_thumb+'\');background-position:center;background-repeat:no-repeat;background-size:auto 70px;"></div><div style="position:absolute;left:90px;right:100px;display:block;height:80px;top:0px"><h4 style="margin-top:6px;font-weight:lighter;font-size:14px;">'+item.goods.name+'</h4><p class="my-dp1">'+item.good_format+'</p></div><div style="position:absolute;width:100px;right:0px;display:block;height:80px;top:0px"><p class="my-dp1 f-r" style="text-align:right;padding-top:3px;padding-right:3px">价格：<span style="color:#D12424">￥'+item.goods.price+'</span><br>×'+item.count+'</p></div><div style="position:absolute;right:0px;bottom:0px;text-align:right">'+pingjia_htm+'</div></div>');
					 
					
					$('#shangpinlist #'+item.goods.id+' button').click(function(){
						if($(this).html()=='评价'){
							document.location.href="pingjia.html?ORDERID="+oid+"&GOODID="+item.goods.id+"&OPENID="+openid;
						}
						 
					});
					
					/*
					.append('<dl class="my-dl1" style="background-color:#f4f4f4;margin-top:2px"><div style=""></div><dt><a href="#"><img src="'+item.goods.image_thumb+'"></a></dt><dd style="width:50%"></dd><div style="clear:both;"></div></dl>');
					*/
					
					 
				});
				$('#order_action button').click(function(){
					if($(this).html()=='支付'){
						//pay(oid);
						var bb=[];
						var aa={};
						aa.NAME="余额支付";
						aa.ACTION=function(){ zhifudialogshow(oid); };
						bb.push(aa);
						aa={};
						aa.NAME="微信支付";
						aa.ACTION=function(){
							pay(oid);
						};
						bb.push(aa);
						toastwithactions("请选择支付方式",bb);
					}else if($(this).html()=='取消'){
						quxiao(oid);
						
					}else if($(this).html()=='确认收货'){
						querenshouhuo(oid);
					}
				});
				 
				
				
				 
			});
		}
		
		function ispingjia(orderid,spid){
			var oo=pingjia_all[orderid];
			if(oo==undefined){
				var url = "/webserver/api/v1/custassess/?format=json&order="+orderid;
				$.getJSON(url, function(data){
					pingjia_all[orderid]=data;
				});
			}
			oo=pingjia_all[orderid];
			if(oo.objects.length>0){
				var ispijia=false;
				$.each(oo.objects,function(index,item){
					var goodid=item.goods.id;
					if(spid==goodid){
						ispijia=true;
					}
				});
				if(ispijia){
					return "";
				}else{
					return '<div class="my-p2" style="border-top:none"><button class="my-btn1 f-r">评价</button></div>';
				}
				
				
				
			}else{
				return '<div class="my-p2" style="border-top:none"><button class="my-btn1 f-r">评价</button></div>';
			}
			
			 
			
		}
		
		function pay(oid){
			if(oid!=-1){
				var url="/weixin/getpayparm/";
				$.post(url,{"orderid":oid},function(aa){
					if (typeof WeixinJSBridge == "undefined"){
						if( document.addEventListener ){
							document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
						}else if (document.attachEvent){
							document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
							document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
						}
					}else{
						onBridgeReady(aa);
					}
				}, "json");
			}
		}
		
		
		function onBridgeReady(aa){
			
			 
			WeixinJSBridge.invoke('getBrandWCPayRequest', {
				"appId" : aa.appId,     //公众号名称，由商户传入     
				"timeStamp" : aa.timeStamp+"",         //时间戳，自1970年以来的秒数     
				"nonceStr"  :  aa.nonceStr, //随机串     
				"package"  :  aa.package,
				"signType"  :  aa.signType,         //微信签名方式 : 
				"paySign"  :  aa.paySign //微信签名 
			},
			function(res){     
				if(res.err_msg == "get_brand_wcpay_request:ok" ) {
				 
					toastwithaction('支付成功',function(){
						document.location.reload();
					});
				}
				
			});
		}
		
		
		function querenshouhuo(oid){
			var aa={};
			aa.id=oid;
			aa.status="确认收货";
			var url = "/webserver/api/v1/order/"+oid+"/";
			doput(url,aa,function(rs){
				if(rs.status=="确认收货"){
					toastwithaction("已确认收货",function(){
						document.location.reload();
					});
					
				}
				 
			});
		}
		
		function quxiao(oid){
			var aa={};
			aa.id=oid;
			aa.status="已取消";
			var url = "/webserver/api/v1/order/"+oid+"/";
			doput(url,aa,function(rs){
				if(rs.status=="已取消"){
					toastwithaction("已取消",function(){
						document.location.reload();
					});
					
				}
				 
			});
		}
		
		
		function payincash(oid){
			if(oid!=-1){
				var url="/weixin/payorder/";
				$.post(url,{"orderid":oid},function(aa){
					if(aa.code=='true'){
						setTimeout(function(){
							 
						
							toastwithaction("支付成功",function(){
								document.location.reload();
								
							});
							
						
						},500);
						
							
					}else{
						setTimeout(function(){
							var bb=[];
							var aa={};
							aa.NAME="去充值";
							aa.ACTION=function(){ document.location.href="xianjinzhanghu.html?OPENID="+openid;};
							bb.push(aa);
						
							toastwithactions("余额不足!?",bb);
							
						
						},500);
						
				
					
					}
				}, "json");
			}
		}
		
		
		function initayouhui(deduid){
			var url="/webserver/api/v1/deduction/?format=json&id="+deduid;
			$.getJSON(url,function(rs){
				var object = rs.objects[0];
				$('#youhui').html(object.name);
				
			
			},'json');
		}
		
		
		
		
		
		
		
		
		
			//在支付前判断  如果没有密码先去设置密码 , 如果有的话 弹出的支付密码输入框....
		
		
		function haspasswordornot(){
			var isok=true;
			var url="/webserver/api/v1/user/?format=json&openid="+openid;
			$.getJSON(url,function(rs){
				var object=rs.objects[0];
			
				var password=object.password;
				if(password==null||password=='null'||password=='undefined'||password==undefined){
					alert('还没有设置密码请先设置会员密码!');
					document.location.href="zhuce.html?OPENID="+openid;
					isok =false;
				}
				
				
			});
			return isok;
			
			
			
		}
		//支付取消按钮
		$('#zhifu_dialog_cancel').click(function(e) {
			$('#zhifudialog_container').hide();
            
        });

		
		
		
		function zhifudialogshow(oid){
			if(!haspasswordornot()){
				return;
			};
			$('#zhifudialog_container').show();
			$('#password11').focus();
			$('#password11').trigger('focus');
			$('.myzhifumima').removeClass('myzhifumimatian');
			$('#password11').val('');
			$('#password11').off('keyup');
			$('#password11').on('keyup',function(){
				var aa=$(this).val();
				var len=aa.length;
				$('.myzhifumima').each(function(index, element) {
                	if(index<len){
						$(this).addClass('myzhifumimatian');
					}else{
						$(this).removeClass('myzhifumimatian');
					}	
            	});
				if(len==6){
					$('#password11').blur();
					checkmima(aa,oid);
				}
			});
			setTimeout(function(){
				$('#zhifu_dialog_body').css('margin-top',$('body').scrollTop()+10);
			},100);
		
		}
		$('.myzhifumima').click(function(e) {
			$('#password11').focus();
			setTimeout(function(){
				
				$('#zhifu_dialog_body').css('margin-top',$('body').scrollTop()+10);
			},100);
        });
		
		function checkmima(aa,oid){
			var url="/webserver/api/v1/user/?format=json&openid="+openid;
			$.getJSON(url,function(rs){
				$('#zhifudialog_container').hide();
				var object=rs.objects[0];
			
				var password=object.password;
				if(aa==password){
					
					payincash(oid);
				}else{
					toast('密码错误');
					
				}
				
				
				
			});
		
		}
		
		$('#zhifudialog_container').css('height',$(document).innerHeight());
	
	</script>
</body>
</html>
